<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org"
      xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <meta charset="UTF-8">
    <title>i-admin-v1.0 后台管理系统 - 登录</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link th:href="@{/css/bootstrap.css}" rel="stylesheet">
</head>
<body>
<div class="container">

    <!--验证当前用户是否为“访客”，即未认证（包含未记住）的用户。-->
    <p shiro:guest="">访客 未认证</a></p>
    <p shiro:user="">已经登录过了</a></p>
    <div class="col-xs-10 col-sm-8 col-md-6 col-lg-4 col-xs-offset-1 col-sm-offset-2 col-md-offset-3 col-lg-offset-4"
         style="margin-top: 30vh;">
        <div class="panel panel-default">
            <div class="panel-heading">登录</div>
            <div class="panel-body">
                <div class="form-group">
                    <input type="text" class="form-control" name="username" placeholder="请输入用户名" value="">
                </div>
                <div class="form-group">
                    <input type="password" class="form-control" name="password" placeholder="请输入密码" value="">
                </div>
                <div class="form-group">
                    <input type="checkbox" name="rememberMe">记住我
                </div>
                <button type="button" class="btn btn-primary btn-block" id="btn-login">登录</button>
            </div>
        </div>
    </div>
</div>

<script th:src="@{/js/jquery.js}"></script>
<script th:src="@{/lib/layer/layer.js}"></script>
<script>

    $('#btn-login').click(function () {
        var username = $('input[name=username]').val();
        var password = $('input[name=password]').val();
        if (!username) {
            layer.msg('用户名不能为空', {icon: 7, time: 1000});
            return false;
        }
        if (!password) {
            layer.msg('密码不能为空', {icon: 7, time: 1000});
            return false;
        }

        login(username, password);
    });


    function login(username, password) {
        $.ajax({
            // url: '[[@{/login}]]',
            url: '[[@{/kickOut/login}]]',
            type: 'post',
            dataType: 'json',
            data: {
                username: username,
                password: password
            },
            success: function (response) {
                if (response.code == 200) {
                    window.location.href = "[[@{/index}]]";
                } else {
                    layer.alert(response.zzhError);
                }
            },
            error: function (response) {
                console.log(response.toString());
            }
        })
    }
</script>
</body>
</html>